Update pending in-person profile queries to consider enrollment expiration#11129
Update pending in-person profile queries to consider enrollment expiration#11129
Conversation
changelog: Bug Fixes, In-person proofing, Add check for expired enrollment in considering pending in-person proofing
Avoid conflicts on queries not expecting linked enrollment
| create(:in_person_enrollment, :pending, user: user, profile: profile) | ||
| fully_registered | ||
| profiles do | ||
| [association(:profile, :with_pii, :in_person_verification_pending, user: instance)] |
There was a problem hiding this comment.
ooo love this cleanup to use the factory associations better
There was a problem hiding this comment.
Yeah, to be honest it was a bit of a nightmare to figure out how to implement this correctly, but it does feel a lot more reliable / portable, and supports overriding trait attributes in a way that's not possible with the lifecycle hooks.
| # See: Idv::Session#create_profile_from_applicant_with_password | ||
|
|
||
| before do |
There was a problem hiding this comment.
style, I'd remove the space between?
| # See: Idv::Session#create_profile_from_applicant_with_password | |
| before do | |
| # See: Idv::Session#create_profile_from_applicant_with_password | |
| before do |
There was a problem hiding this comment.
Hm, yeah. The padding line was intentional to try to "link" it more with the context block than the before block. But maybe in that case the comment should live above the context line? Not sure how I feel about this.
There was a problem hiding this comment.
I guess my thinking is the context description is what we want to happen, the before block (or sometimes a let) is how we want that to happen, and in this case, the comment clarifies the how
| # See: Idv::Session#create_profile_from_applicant_with_password | ||
|
|
||
| before do | ||
| profile.in_person_enrollment.update(status: :establishing, profile: nil) |
There was a problem hiding this comment.
When would a Profile be associated with an InPersonEnrollment and the InPersonEnrollment have profile set to nil?
There was a problem hiding this comment.
Does the comment above help clarify?
identity-idp/spec/models/profile_spec.rb
Lines 68 to 71 in d1a1bc7
There was a problem hiding this comment.
maybe clarify that it's still linked to the user via the in_person_enrollment.user_id?
app/models/profile.rb
Outdated
|
|
||
| def in_person_verification_pending? | ||
| in_person_verification_pending_at.present? | ||
| in_person_verification_pending_at.present? && !in_person_enrollment&.expired? |
There was a problem hiding this comment.
Why is InPersonEnrollment not Expired checked rather than InPersonEnrollment is pending?
There was a problem hiding this comment.
That's a good call, I'll update to have them in sync.
app/models/profile.rb
Outdated
| def self.in_person_verification_pending | ||
| where.not(in_person_verification_pending_at: nil) | ||
| where.not(in_person_verification_pending_at: nil). | ||
| left_outer_joins(:in_person_enrollment).where.not(in_person_enrollment: { status: :expired }) |
|
@aduth Thanks for digging into this. After further investigation, Team Joy is going to move forward with updating the data (setting profile.in_person_verification_pending_at to nil in the USPS job) with the PR and then backfilling the data like what you are doing in PR, with some updates. I think we can close this pull request now. |
Makes sense to me 👍 |
|
Though I'd like to salvage some of the spec factory improvements here, I'll put together a pull request for just those changes. |
🛠 Summary of changes
Updates queries for pending in-person profiles profiles to consider whether the associated enrollment is expired.
This follows #11105 (LG-14231), which updated the proofing results job to reset the profile pending timestamp for an expired enrollment. The intent with these changes is to accommodate both new and old profiles which may or may not have this value reset.
This is a (temporary?) alternative to a solution which would involve updating database records to reset the timestamp for profiles associated with expired enrollments: #11130
📜 Testing Plan
Override
config/application.ymlto prevent results job from automatically marking pending profiles as successful in local development:rails consoleInPersonEnrollment.last.update(status: :expired)Before: You'd be redirected to the account page (wrong), and the account page would raise an exception when trying to access
due_dateproperty on the pending enrollmentAfter: You're redirected into the identity verification flow